package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.log.anno.SysOperLog;
import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductSaveDTO;
import com.atguigu.spzx.model.dto.product.ProductSearchDTO;
import com.atguigu.spzx.model.vo.common.R;
import com.atguigu.spzx.model.vo.product.ProductVO;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/product")

@Tag(name = "商品管理模块")
public class ProductController {
    @Resource
    ProductService productService;
    //updateAuditStatus/7/-1
    @Operation(summary = "商品审批")
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public R updateAuditStatus(@PathVariable("id")Long id,
                          @PathVariable("auditStatus")Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return R.ok();
    }
    @Operation(summary = "商品上下架")
    @GetMapping("updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id")Long id,
                          @PathVariable("status")Integer status){
        productService.updateStatus(id,status);
        return R.ok();
    }
    @Operation(summary = "更新商品")
    @PutMapping("updateById")
    public R updateById(@RequestBody ProductSaveDTO productSaveDTO){
        productService.updateById(productSaveDTO);
        return R.ok();
    }
    ///admin/product/product/getById/7
    @Operation(summary = "根据id查询商品")
    @GetMapping("getById/{id}")
    public R getById(@PathVariable("id")Long id){
        ProductSaveDTO productSaveDTO = productService.getById(id);
        return R.ok("item",productSaveDTO);
    }
    @Operation(summary = "新增商品")
    @PostMapping("save")
    public R save(@RequestBody ProductSaveDTO productSaveDTO){
        productService.save(productSaveDTO);
        return R.ok();
    }
    @Operation(summary = "根据id删除商品")
    @DeleteMapping("deleteById/{id}")
    public R deleteById(@PathVariable("id")Long id){
        productService.deleteById(id);
        return R.ok();
    }
    @SysOperLog(title = "商品管理模块")
    @Operation(summary = "条件查询商品分页列表")
    @GetMapping("{pageNum}/{pageSize}")
    public R list(@PathVariable("pageNum")Integer pageNum,
                  @PathVariable("pageSize")Integer pageSize,
                  ProductSearchDTO productSearchDTO){
        PageInfo<ProductVO> pageInfo =  productService.list(pageNum,pageSize,productSearchDTO);
        return R.ok("page" , pageInfo);
    }
}
